package com.example.springbootlog4j.util;

import org.apache.log4j.Logger;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@EnableScheduling
public class StaticScheduleJob {

    private static Logger log = Logger.getLogger(StaticScheduleJob.class);

    /**
     * 上次开始执行时间点后5秒再次执行
     */
    @Scheduled(fixedRate = 5000)
    public void job3() {
        log.info("执行任务job3："+DateUtil.getNowDate(DateUtil.TIME_FORMAT_MINUTE));
    }

    /**
     * 上次执行完毕时间点后3秒再次执行
     */
    @Scheduled(fixedDelay = 3000)
    public void job2() {
        log.info("执行任务job2："+DateUtil.getNowDate(DateUtil.TIME_FORMAT_MINUTE));
    }

    /**
     * 每隔10秒执行一次（按照 corn 表达式规则执行）
     */
    @Scheduled(cron = "0/10 * * * * ?")
    public void job1() {
        log.info("执行任务job1："+DateUtil.getNowDate(DateUtil.TIME_FORMAT_MINUTE));
    }


}
